package com.semlab.client.fwk.ap;

import java.util.List;
import java.util.logging.Logger;

import com.google.gwt.activity.shared.Activity;
import com.google.gwt.activity.shared.ActivityMapper;
import com.google.gwt.place.shared.Place;

public class CompositeActivityMapper implements ActivityMapper {

	private static final Logger log = Logger.getLogger(CompositeActivityMapper.class.getName());

	private List<MappingsEntry> mappings;

	public CompositeActivityMapper(List<MappingsEntry> mappers) {
		this.mappings = mappers;
	}

	@Override
	public Activity getActivity(Place place) {
		for (MappingsEntry mappingsEntry : mappings) {
			if (mappingsEntry.getPlace().equals(place)) {
				Activity activity = mappingsEntry.getActivityMapper().getActivity(place);
				if (activity != null) {
					//duplicate places will be ignored, place id must be unique for one container
					return activity;
				}
			}
		}
		return null;
	}

}
